enyo.kind({
    name: "MyApps.DemoDaysList",
    kind: enyo.VFlexBox,
    events: {
        onBack: "",
    },
    components: [    /**
     * service
     */
    {
        name: "getData",
        kind: "WebService",
        url: "http://query.yahooapis.com/v1/public/yql?q=select * from xml where url= 'http://golfplus.mobile2you.fr/demo_days.xml' &format=json&callback=",
        onSuccess: "gotData",
        onFailure: "gotDataFailure"
    },    /**
     * Layout
     */
    {
        name: "pane",
        kind: "Pane",
        flex: 1,
        components: [{
            kind: "VFlexBox",
            components: [{
                name: "list",
                kind: "VirtualRepeater",
                flex: 1,
                onSetupRow: "listSetupRow",
                components: [{
                    kind: "Item",
                    layoutKind: "VFlexLayout",
                    components: [{
                        name: "when",
                        className: "demodaysdate",
                    }, {
                        name: "description",
                        className: "demodaysdescription",
                    }, {
                        name: "club",
                        className: "demodaysclubstore",
                    }, {
                        name: "store",
                        className: "demodaysclubstore",
                    }],
                }]
            }, ]
        }, ]
    }, ],
    
    create: function(){
        this.inherited(arguments);
        this.data = [];
        this.club = [];
        this.store = [];
        this.$.getData.call();
    },
    gotData: function(inSender, inResponse){
        this.data = inResponse.query.results['demo-days']['demo-day'];
        console.log("got Data");
        this.$.pane.render();
    },
    
    
    gotDataFailure: function(inSender, inResponse){
        console.log("got failure from getData");
    },
    listSetupRow: function(inSender, inRow){
        var f = this.data[inRow];
        if (f) {
        
            var date_string = f.when.content;
            var x = date_string.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z/);
            var d = new Date(x[1], x[2], x[3], x[4], x[5], x[6]);
            
            this.$.when.setContent(d.toLocaleDateString());
            this.$.description.setContent(f.description);
            this.$.club.setContent("Golf: " + f.golf.nom);
            this.$.store.setContent("Magasin: " + f.shop.nom);
            return true;
        }
    },
});



